﻿
namespace TinyMceWrapper
{

    #region [ Imports ]

    using System;
    using System.Globalization;
    using System.Linq;
    using System.Text.RegularExpressions;

    #endregion

    internal static class Utilities
    {

        #region [ Public Static Methods ]

        public static void NotNull<T>(T value, string parameterName)
        {
            if (value == null)
                throw new ArgumentNullException(parameterName);
        }

        public static bool NotNullOrEmpty(string value, string parameterName)
        {
            return NotNullOrEmpty(value, parameterName, true);
        }

        public static bool NotNullOrEmpty(string value, string parameterName, bool throwException)
        {
            bool res = !(string.IsNullOrEmpty(value));

            if (!res && throwException)
                throw new ArgumentNullException(parameterName);

            return res;
        }

        public static bool IsNumeric(string value)
        {
            double res;
            return IsNumeric(value, out res);
        }

        public static bool IsNumeric(string value, out double result)
        {
            return double.TryParse(value, out result);
        }

        public static bool IsBoolean(string value)
        {
            bool res;
            return IsBoolean(value, out res);
        }

        public static bool IsBoolean(string value, out bool result)
        {
            return bool.TryParse(value, out result);
        }

        public static void ThrowOnFailure<TException>(bool clause, params object[] args) where TException : Exception
        {
            if (clause) throw (Exception)Activator.CreateInstance(typeof(TException), args);
        }

        public static void ThrowOnFailure<TException>(bool clause, Func<object[]> callback) where TException : Exception
        {
            if (clause) throw (Exception)Activator.CreateInstance(typeof(TException), callback());
        }

        #endregion

    }

}
